<template>
  <div>
    <el-form :model="search_form" class="search_prod" label-width="120px">
      <el-form-item label="用户名">
        <el-col :span="4">
          <el-col :span="16" class="search_input_width">
            <el-input size="small" clearable v-model="search_form.username"></el-input>
          </el-col>
        </el-col>
        <el-col class="tr col_label" :span="3">用户昵称&nbsp;&nbsp;&nbsp;</el-col>
        <el-col :span="4">
          <el-col :span="16" class="search_input_width">
            <el-input size="small" clearable v-model="search_form.nickname"></el-input>
          </el-col>
        </el-col>
        <el-col class="tr col_label" :span="3">商品标题&nbsp;&nbsp;&nbsp;</el-col>
        <el-col :span="4">
          <el-col :span="16" class="search_input_width">
            <el-input size="small" clearable v-model="search_form.title"></el-input>
          </el-col>
        </el-col>
      </el-form-item>
      <el-form-item label="供应商用户名">
        <el-col :span="4">
          <el-col :span="16" class="search_input_width">
            <el-input size="small" clearable v-model="search_form.s_username"></el-input>
          </el-col>
        </el-col>
        <el-col class="tr col_label" :span="3">供应商昵称&nbsp;&nbsp;&nbsp;</el-col>
        <el-col :span="4">
          <el-col :span="16" class="search_input_width">
            <el-input size="small" clearable v-model="search_form.s_nickname"></el-input>
          </el-col>
        </el-col>
        <el-col class="tr col_label" :span="3">时间&nbsp;&nbsp;&nbsp;</el-col>
        <el-col :span="4">
          <el-col :span="22" class="search_time_y_width">
            <el-date-picker
              style="width:100%"
              v-model="createTime"
              type="datetimerange"
              size="small"
              align="right"
              unlink-panels
              clearable
              value-format="timestamp"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions2"
            ></el-date-picker>
          </el-col>
        </el-col>
      </el-form-item>

      <el-form-item>
        <el-row class="tl">
          <el-col :span="24">
            <el-button size="mini" type="primary" @click="order_search_btn">查询</el-button>
            <el-button size="mini" type="primary" @click="del_search_btn">一键清除</el-button>
          </el-col>
        </el-row>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  name: "card_search",
  data() {
    return {
      status_option: [
        {
          label: "未发放",
          value: "0"
        },
        {
          label: "已发放",
          value: "1"
        }
      ],
      search_form: {
        username: "",
        nickname: "",
        title: "",
        s_username: "",
        s_nickname: "",
        created_time_begin: "",
        created_time_end: ""
      },
      createTime: [],
      pickerOptions2: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      }
    };
  },
  components: {},
  methods: {
    del_search_btn() {
      this.search_form = {
        username: "",
        nickname: "",
        title: "",
        createTime: [],
        s_username: "",
        s_nickname: ""
      };
      this.$emit("send_search", this.search_form);
    },
    order_search_btn() {
      this.$emit("send_search", this.search_form);
    }
  },
  watch: {
    createTime(val) {
      if (val != null) {
        this.search_form.created_time_begin = this.$fnc.phptime(val[0]);
        this.search_form.created_time_end = this.$fnc.phptime(val[1]);
      } else {
        this.search_form.created_time_begin = "";
        this.search_form.created_time_end = "";
      }
    }
  }
};
</script>
<style scoped>
</style>
